package logic

import (
	"class/models"
	"context"

	"class/classrpc/classrpc"
	"class/classrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentListLogic {
	return &CommentListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论列表
func (l *CommentListLogic) CommentList(in *classrpc.CommentListRequest) (*classrpc.CommentListResponse, error) {
	// todo: add your logic here and delete this line

	var comments []models.Comment

	models.DB.Debug().Find(&comments)

	var commentList []*classrpc.CommentList
	for _, comment := range comments {
		list := classrpc.CommentList{
			Content:  comment.Content,
			UserId:   int64(comment.UserId),
			CourseId: int64(comment.CourseId),
		}
		commentList = append(commentList, &list)
	}

	return &classrpc.CommentListResponse{
		List: commentList,
	}, nil
}
